<?php
class jsMod extends commonMod
{
    public function __construct()
    {
        parent::__construct();
    }

	function mobilejs(){
		echo<<<JS
function submitOrder(UserName, Phone, OrderInfo, _oid) {
    var zz = /^1[3|4|5|8][0-9]\d{4,8}$/;
    $("#ErrorInfo").removeAttr("class").addClass("red pl10");
    if ($("#" + UserName + "").val() == "" || $("#" + UserName + "").val() == "Please enter your name") {
        $("#ErrorInfo").empty();
        $("#ErrorInfo").append("Please enter your name");
        return;
    } else if ($("#" + Phone + "").val() == "" || $("#" + Phone + "").val() == "Please enter your phone") {
        $("#ErrorInfo").empty();
        $("#ErrorInfo").append("Please enter your phone");
        return;
    } else if (!zz.test($("#" + Phone + "").val())) {
        $("#ErrorInfo").empty();
        $("#ErrorInfo").append("Phone number format is incorrect");
        return;
    } else if ($("#" + OrderInfo + "").val() == "" || $("#" + OrderInfo + "").val() == "Please enter your content") {
        $("#ErrorInfo").empty();
        $("#ErrorInfo").append("Please enter your content");
        return;
    }  else if (_oid <= 0) {
        $("#ErrorInfo").empty();
        $("#ErrorInfo").append("Submit data is incorrect, please try again");
    } else {
        $("#ErrorInfo").empty();
        $.post("/index.php/form/ajax/", {
            faid: _oid,
            name: $("#" + UserName + "").val(),
            tel: $("#" + Phone + "").val(),
            content: $("#" + OrderInfo + "").val(),
            time: $("#time").val(),
            form: $("#form").val(),
            ip: $("#ip").val()
        }, function(msg) {
            var sta = gav(msg, "state");
            var sMsg = gav(msg, "msg");
            $("#ErrorInfo").append(sMsg);
            if (sta == "1") {
                $("#ErrorInfo").removeAttr("class").addClass("green pl10");
                $("#ErrorInfo").show(1000, function() {
                    $("#" + UserName + "").val("");
                    $("#" + Phone + "").val("");
                    $("#" + OrderInfo + "").val("");

                    $("#" + UserName + "").val("Please enter your name");
                    $("#" + Phone + "").val("Please enter your phone");
                    $("#" + OrderInfo + "").val("Please enter your content");
                });
            } else {

            }
        });
    }
}

function gav(xMsg, key) {
    var jMsg = $(xMsg);
    var s = $(jMsg.find("node[key=" + key + "]")).text();
    return s;
}
JS;
	}
	
	function tomobile(){
		$mobile = $this->config['MOBILE_DOMAIN'];
		if($mobile){
		echo<<<JS
function is_mobile() {
    var regex_match = /(nokia|iphone|android|motorola|^mot- |softbank|foma|docomo|kddi|up.browser|up.link|htc|dopod|blazer|netfront|helio|hosin|huawei|novarra|CoolPad|webos|techfaith|palmsource|blackberry|alcatel|amoi |ktouch|nexian|samsung|^sam-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo|maui|symbian|smartphone|midp|wap|phone|windows  ce|iemobile|^spice|^bird|^zte-|longcos|pantech|gionee|^sie-|portalmmm|jigs browser|hiptop|^benq|haier|^lct|operas*mobi|opera*mini|320x320|240x320|176x220)/i;
    var u = navigator.userAgent;
    if (null == u) {
        return true;
    }
    var result = regex_match.exec(u);
    if (null == result) {
        return false
    } else {
        return true
    }
}
var url = window.location.href;
mobile = "$mobile";

url = url.replace("http://", "");
var temp = url.split("/");
if (is_mobile()) {
    if (url.indexOf(mobile) < 0) {
        var surl = "http://" + mobile;
        for (var i = 0; i < temp.length; i++) {			
            if (i != 0){
                surl = surl + "/" + temp[i];
			}
        }
        document.location.href = surl;
    }
}
else {
    if (url.indexOf("mobile") > 0) {
        //document.location.href = url.replace("/mobile", "");
    }
}
JS;
		}
	}

}

?>